﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using Edgar.Entities.MasterData;
using System.IO;

namespace Edgar.Logic
{
    public class RulebookLoader
    {
        public Rulebook Load(string rulebookPath)
        {
            using (TextReader tr = new StreamReader(rulebookPath))
            {
                XmlSerializer serializer = new XmlSerializer(typeof(Rulebook));
                try
                {
                    object deserialized = serializer.Deserialize(tr);
                    return (Rulebook)deserialized;
                }
                catch (FileNotFoundException e)
                {
                    throw new Exception("Rulebook Datei nicht auffindbar!\n" + e.Message);
                }
                catch (InvalidOperationException e)
                {
                    throw new Exception("Rulebook Datei fehlerhaft!\n" + e.Message);
                }
            }
        }
    }
}
